package com.atguigu.exer;

public class ThreadDemo3 extends Thread{
    private static int ticket=1000;

    public static void main(String[] args) {
        ThreadDemo3 threadDemo3=new ThreadDemo3();
        ThreadDemo3 threadDemo31=new ThreadDemo3();
        ThreadDemo3 threadDemo32=new ThreadDemo3();
        threadDemo3.setName("窗口1");
        threadDemo31.setName("窗口2");
        threadDemo32.setName("窗口3");
        threadDemo3.start();
        threadDemo31.start();
        threadDemo32.start();
    }

    public void run(){
        while(true){
            synchronized(ThreadDemo3.class) {
                if (ticket > 0) {
                    System.out.println(currentThread().getName() + "在售票，票号为：" + ticket);
                    ticket--;
                } else {
                    break;
                }
            }
        }
    }
}
